package com.wnx.job.common.api;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;


@Data
public class ResultData<T> implements Serializable {

	/**
	 * 状态码
	 */
	@ApiModelProperty("状态码")
	private long code;
	/**
	 * 提示消息
	 */
	@ApiModelProperty("提示消息")
	private String message;

	/**
	 * 交互数据
	 */
	@ApiModelProperty("交互数据")
	private T data;

	protected ResultData() {
	}

	protected ResultData(long code, String message, T data) {
		this.code = code;
		this.message = message;
		this.data = data;
	}

	/**
 	 * 成功返回结果
	 */
	public static <T> ResultData<T> success(String message) {
		return success(ResultCode.SUCCESS.getCode(),message,null);
	}
	public static <T> ResultData<T> success(T data) {return success(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(), data);}
	public static <T> ResultData<T> success(long code, String message) {
		return success(code,message,null);
	}
	public static <T> ResultData<T> success(String message, T data) {
		return success(ResultCode.SUCCESS.getCode(),message,data);
	}
	public static <T> ResultData<T> success(long code, String message, T data) {
		ResultData<T> resultData = new ResultData<T>();
		resultData.setCode(code);
		resultData.setMessage(message);
		resultData.setData(data);
		return resultData;
	}


	/**
	 * 失败返回结果
	 */
	public static <T> ResultData<T> fail(String message) {return fail(ResultCode.FAILED.getCode(), message, null);}
	public static <T> ResultData<T> fail(T data) {return fail(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage(),data);}
	public static <T> ResultData<T> fail(long code,String message) {return fail(code,message,null);}
	public static <T> ResultData<T> fail(String message,T data) {return fail(ResultCode.FAILED.getCode(),message,data);}
	public static <T> ResultData<T> fail(long code, String message, T data) {
		ResultData<T> r = new ResultData<T>();
		r.setCode(code);
		r.setMessage(message);
		r.setData(data);
		return r;
	}



	/**
	 * 未登录返回结果
	 */
	public static <T> ResultData<T> unauthorized(T data) {
		return new ResultData<T>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data);
	}

	/**
	 * 未授权返回结果
	 */
	public static <T> ResultData<T> forbidden(T data) {
		return new ResultData<T>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data);
	}

	/**
	 * 参数验证失败返回结果
	 */
	public static <T> ResultData<T> validateFailed() {return fail(ResultCode.VALIDATE_FAILED.getCode(),ResultCode.VALIDATE_FAILED.getMessage());}


	/**
	 * 参数验证失败返回结果
	 * @param message 提示信息
	 */
	public static <T> ResultData<T> validateFailed(String message) {return fail(ResultCode.VALIDATE_FAILED.getCode(), message, null);}




}
